use aiqchain::{Blockchain, Transaction};

fn truncate_hash(hash: &str, length: usize) -> String {
    if hash.len() <= length {
        hash.to_string()
    } else {
        format!("{}...", &hash[..length])
    }
}

fn main() {
    let mut chain = Blockchain::new();
    
    // 创建第一个交易
    let tx1 = Transaction {
        sender: "genesis".to_string(),
        receiver: "user1".to_string(),
        amount: 100,
        signature: "".to_string(),
    };
    
    // 创建第二个交易
    let tx2 = Transaction {
        sender: "user1".to_string(),
        receiver: "user2".to_string(),
        amount: 50,
        signature: "".to_string(),
    };

    // 添加区块
    chain.add_block(vec![tx1]);
    chain.add_block(vec![tx2]);

    println!("区块链状态：");
    for (index, block) in chain.chain.iter().enumerate() {
        println!(
            "区块 {}: 哈希 {} 前哈希 {} 交易数 {}",
            index,
            truncate_hash(&block.hash, 8),
            truncate_hash(&block.previous_hash, 8),
            block.transactions.len()
        );
    }
}
